package com.panopset.gui;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;

/**
 * Test the Osgw object, by putting an Osgw in a window and doing
 * some simple animation.
 *
 * @author Karl Dinwiddie
 *
 */
public class TestOsgw {
    static int x = 0;

    public static void main(String... s) {
        new TestOsgw().go();
    }

    Osgw osgw;

    Osgw getOsgw() {
        if (osgw == null) {
            osgw = new Osgw(100,200){

                @Override
                public void paintCycle(Graphics2D g) {
                    g.setColor(Color.yellow);
                    g.fillRect(0,0,1000,1000);
                    g.setColor(Color.blue);
                    g.drawOval(x++, 50, 12,12);
                    if (x > 100) x = 0;
                }

            };
        }
        return osgw;
    }
    public void go() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.addWindowListener(new WindowListener() {

            @Override
            public void windowActivated(WindowEvent e) {
                // nothing to do here.
            }

            @Override
            public void windowClosed(WindowEvent e) {
                Osgw.close();
            }

            @Override
            public void windowClosing(WindowEvent e) {
                // nothing to do here.
            }

            @Override
            public void windowDeactivated(WindowEvent e) {
                // nothing to do here.
            }

            @Override
            public void windowDeiconified(WindowEvent e) {
                // nothing to do here.
            }

            @Override
            public void windowIconified(WindowEvent e) {
                // nothing to do here.
            }

            @Override
            public void windowOpened(WindowEvent e) {
                // nothing to do here.
            }

        });
        f.setTitle("Test OSGW");
        f.setBounds(100,100,600,600);
        f.setVisible(true);
        f.add(getOsgw().getPanel());
    }
}
